package com.hqyj.excepiton;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;

/**
 * 项目:exam-springboot-230701
 * 描述:
 * 时间:2023/10/7 9:50
 * 作者:admin
 * 版本:1.0
 **/
@RestControllerAdvice(basePackages = "com.hqyj.controller")
public class MyAdvice {

    /**
     * 处理题库业务的异常通知
     * @param e
     * @return
     */
    @ExceptionHandler(QuestionException.class)
    public HashMap<String,Object> QuestionException(QuestionException e){
        HashMap<String,Object>  map = new HashMap<String,Object>();
        map.put("code",e.getCode());
        map.put("msg",e.getMsg());
        map.put("info",e.getInfo());
        return map;
    }
    /**
     * 处理jwt认证业务的异常通知
     * @param e
     * @return
     */
    @ExceptionHandler(JwtException.class)
    public HashMap<String,Object> JwtException(JwtException e){
        HashMap<String,Object>  map = new HashMap<String,Object>();
        map.put("code",e.getCode());
        map.put("msg",e.getMsg());
        map.put("info",e.getInfo());
        return map;
    }
    /**
     * 处理权限业务的异常通知
     * @param e
     * @return
     */
    @ExceptionHandler(PowerException.class)
    public HashMap<String,Object> PowerException(PowerException e){
        HashMap<String,Object>  map = new HashMap<String,Object>();
        map.put("code",e.getCode());
        map.put("msg",e.getMsg());
        map.put("info",e.getInfo());
        return map;
    }



}
